<!-- Vip会员页面 -->
<template>
  <div class="container">
    <KPTop title="VIP会员"></KPTop>
    <div class="line"></div>
    <div class="user-info">
      <div class="avatar">
        <img src="http://1.14.239.98/storage/images/jQK5rnoGHL9YKTs28iuAZxZT4DjmFF7pDhws72bt.png" />
      </div>
      <div class="role-info">
        <div class="info">
          <div>您的月度会员2023-08-14 16:56:56到期</div>
          <div>购买后将会有效期顺延</div>
        </div>
      </div>
    </div>
    <div class="role-item-box">
      <div
        :class="num==item.id?'role-item active':'role-item'"
        v-for="item in vipMsg"
        :key="item.id"
        @click.stop="changeNum(item.id)"
      >
        <div class="name">{{item.name}}</div>
        <div class="price">
          <span class="small">￥</span>
          {{item.charge}}
        </div>
        <div class="desc" v-for="(i,index) in item.desc_rows" :key="index">
          <div>{{i}}</div>
        </div>
      </div>
    </div>
    <div class="bottom-bar" @click.stop="buyVIP">购买会员</div>
  </div>
</template>

<script>
import KPTop from "@/components/KPTop.vue";
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  //import引入的组件需要注入到对象中才能使用
  components: { KPTop },
  data() {
    //这里存放数据
    return {
      vipMsg: [],
      num: 0
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    changeNum: function(num) {
      this.num = num;
    },
    buyVIP: function() {
      let msgId = this.num;
      console.log(msgId);
      this.$router.push({
        path: "/member/bymsg",
        query: {
          byMsg: this.vipMsg[msgId - 1]
        }
      });
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.$request.get("/api/v2/roles").then(res => {
      this.vipMsg = res.data;
      console.log(this.vipMsg);
    });
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {
    let msgId = this.num;
    console.log(msgId);
  }, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {} //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang="less" scoped>
.container {
  box-sizing: border-box;
  padding-top: 50px;
  background: #f6f6f6;
}

.user-info {
  width: 100%;
  height: auto;
  float: left;
  display: flex;
  padding: 20px 15px;
  box-sizing: border-box;
  margin-top: 15px;
  margin-bottom: 15px;
  background-color: white;
  .avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    img {
      width: 48px;
      height: 48px;
      border-radius: 50%;
    }
  }

  .role-info {
    padding-top: 4px;
    margin-left: 15px;
    flex: 1;
    font-size: 13px;
    font-weight: 400;
    color: rgba(51, 51, 51, 1);
    line-height: 20px;
  }
}

.role-item-box {
  width: 100%;
  height: auto;
  float: left;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  box-sizing: border-box;
  padding: 15px;

  .role-item {
    width: calc(50% - 5px);
    height: auto;
    float: left;
    padding: 15px;
    box-sizing: border-box;
    border-radius: 8px;
    margin-bottom: 15px;
    border: 1px solid white;
    background-color: white;

    &:nth-of-type(even) {
      margin-left: 10px;
    }

    &.active {
      border: 1px solid rgba(225, 165, 0, 1);
      background: rgba(255, 237, 237, 1);
    }

    .name {
      width: 100%;
      height: auto;
      float: left;
      font-size: 14px;
      font-weight: 600;
      color: rgba(225, 165, 0, 1);
      line-height: 14px;
      margin-bottom: 20px;
    }

    .price {
      width: 100%;
      height: auto;
      float: left;
      font-size: 28px;
      font-weight: 600;
      color: rgba(51, 51, 51, 1);
      line-height: 24px;
      margin-bottom: 15px;

      .small {
        font-size: 18px;
      }
    }

    .desc {
      width: 100%;
      height: auto;
      float: left;
      font-size: 12px;
      font-weight: 400;
      color: rgba(102, 102, 102, 1);
      line-height: 18px;
    }
  }
}

.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 49px;
  background-color: #cea200;
  line-height: 49px;
  text-align: center;
  color: white;

  &:active {
    background-color: rgba(#cea200, 0.9);
  }
}
</style>

<style>
#page {
  background-color: #f8f8f8;
}
</style>